
var Env_Path_Abstract = Class.create();
Env_Path_Abstract.construct = function() {
    ////this.publicMember = null;		// use "this" to define public member
    ////var privateMember = null;       // use "var" to define private member

	var pathStr = null;
	var shell = null;

	//this.regPath = "HKEY_CURRENT_USER\\Environment\\Path";
 
    // define initialize method
    this.initialize = function(regPath) {
		this.regPath = regPath;
    }

    this.toString = function() {
        return this.getPathStr();
    }


	this.add = function (path) {
		if (!this.exists(path)) {
			this._add(path);
		}
	}

	this._add  = function (path) {
		var pathStr = this.getPathStr();
		pathStr += ';' + path;
		var shell = this.getShell();
		////WScript.Echo(pathStr); 
		this.pathStr = shell.RegWrite(this.regPath, pathStr);
	}

	this.exists = function (path) {
		var temp = this.getPathStr().split(';');
		 
		for (var i=0; i<temp.length; i++) {
			var nPath = temp[i];
			if(nPath == path) {
				return true;
			}			
		}
		return false;
	}

	this.getPathStr = function() {
		//if (!this.pathStr) {
			try {
				var shell = this.getShell();
				this.pathStr = shell.RegRead(this.regPath);
			} catch (e) {

				this.pathStr = '';
				shell.RegWrite(this.regPath, '');
				
			}

		//}
		return this.pathStr;
	}

	this.getShell = function() {
		if(!this.shell) {
			this.shell = WScript.CreateObject("WScript.Shell");
		}
		return this.shell;
	}


}
Class.register(Env_Path_Abstract, 'Env.Path.Abstract');
Env_Path_Abstract = null;


